package cn.bone.ou.scheduled.config;

import cn.bone.base.dict.Dict;
import cn.bone.ou.scheduled.job.OpLoggerExpireJob;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.CronTriggerFactoryBean;
import org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean;

@Configuration
public class OpLoggerExpireJobConfig {

    @Bean(name="loggerExpireJobBean")
    public MethodInvokingJobDetailFactoryBean loggerExpireJobBean(OpLoggerExpireJob loggerExpireJob){
        MethodInvokingJobDetailFactoryBean jobDetail = new MethodInvokingJobDetailFactoryBean();
        jobDetail.setConcurrent(false);                 // 是否并发
        jobDetail.setName("bone-loggerExpireJob");              // 任务的名字
        jobDetail.setGroup("bone");                       // 任务的分组
        jobDetail.setTargetObject(loggerExpireJob);        // 被执行的对象
        jobDetail.setTargetMethod("execute");           // 被执行的方法
        return jobDetail;
    }

    @Bean(name = "loggerTrigger")
    public CronTriggerFactoryBean loggerTrigger(
            @Qualifier("loggerExpireJobBean") MethodInvokingJobDetailFactoryBean loggerExpireJobBean){
        CronTriggerFactoryBean trigger = new CronTriggerFactoryBean();
        trigger.setJobDetail(loggerExpireJobBean.getObject());
        trigger.setCronExpression(Dict.CronDict.loggerCron);
        trigger.setName("bone-loggerTrigger");
        return trigger;
    }
}
